package com.fitness.fitness.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fitness.fitness.modal.resource.entity.Venue;
import com.fitness.fitness.modal.resource.params.VenuePageQueryParams;
import com.fitness.fitness.modal.resource.vo.VenueVO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface VenueMapper extends BaseMapper<Venue> {
    @Select("<script>select * from t_venue e"
            + " <where>"
            + "<if test='queryParams.keywords != null and queryParams.keywords.trim() neq \"\"'>"
            + " AND (e.name like  CONCAT('%',#{queryParams.keywords},'%') or e.sn like CONCAT('%',#{queryParams.keywords},'%'))"
            + "</if>"
            + "<if test='queryParams.status != null'>"
            + " AND e.status = #{queryParams.status} "
            + "</if>"
            + "</where>"
            +"</script>")
    Page<Venue> getVenuePage(Page<VenueVO> page, VenuePageQueryParams queryParams);

    @Select("SELECT * FROM t_venue tc WHERE id IN (SELECT venue_id FROM t_course_schedule tcs " +
            "WHERE status = 0 AND (start_time > #{endTime} OR end_time < #{startTime}))")
    List<Venue> queryAvailableVenue(String startTime, String endTime);

    @MapKey("id")
    @Select("select * from t_venue")
    Map<Long, Venue> getVenueMap();
}
